package com.only4play.portal.common.error;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.io.Serializable;

/**
 * @author liyuncong
 * @version 1.0
 * @file PortalError
 * @brief PortalError
 * @details PortalError
 * @date 2024-06-07
 *
 * Edit History
 * ----------------------------------------------------------------------------
 * DATE                     NAME               DESCRIPTION
 * 2024-06-07               liyuncong          Created
 */

@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@Builder
public class PortalError implements Serializable {

    private int errorCode;

    private String errorMsg;

    private String json;

    public static PortalError fromJson(String json) {
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            return objectMapper.readValue(json, PortalError.class);
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }
    }
}
